<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery-3.3.1.js"></script>
</head>

<body>
    <div class="container">
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
    </div>
</body>

</html>
<script>
    $('body').click(function () {
        hammerTime()
    })
    function hammerTime() {
        $('.box').each(function () {
            let deg = 45
            let count = Math.round(Math.random())
            let degs = deg * count + 'deg'
            $(this).css('transform', `rotate(${degs})`)
        })
    }
</script>

<style>
    body {
        height: 100vh;
        background-color: #fff;
        padding: 30px;
    }

    .container {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: wrap;
        width: 250px;
        height: 250px;
    }

    .box {
        width: 50px;
        height: 50px;
        position: relative;
    }

    .box::before {
        content: "";
        position: absolute;
        width: 100%;
        height: 2px;
        background-color: #000;
        transform: rotate(45deg);
        transition: .3s;
    }
</style>